from ._base import db
from flask.ext.login import UserMixin


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True)

    create_time = db.Column(db.DateTime, nullable=False)
    create_person = db.Column(db.Integer, nullable=False)
    edit_time = db.Column(db.DateTime, nullable=False)
    edit_person = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer, nullable=True, default=1)  # 1：普通用户；2：部门用户；99：管理员
    is_valid = db.Column(db.Integer, nullable=True, default=1)  # 0：停用；1：正常；2：锁；


class UserDept(db.Model):
    __tablename__ = "user_dept"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=True)
    Dept_id = db.Column(db.Integer, unique=True)

    create_time = db.Column(db.DateTime, nullable=False)
    create_person = db.Column(db.Integer, nullable=False)
    edit_time = db.Column(db.DateTime, nullable=False)
    edit_person = db.Column(db.Integer, nullable=False)
    is_valid = db.Column(db.Integer, nullable=True, default=1)  # 0：停用；1：正常；2：锁定；
